aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/[username]
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-09-28 20:21:58 -0700
committerAdam Soltys <[email protected]>2022-09-28 20:21:58 -0700
commit9e07792fcdd0ba0b7c07a20fe83db54597388e26 (patch)
treea79d54ea6b864abc1953a3aafcc3ff630c1b06e5 /src/routes/[username]
parent732f77dcabc45a3df578a1a03c457b9c94866619 (diff)
downloadcoinos-ui-9e07792fcdd0ba0b7c07a20fe83db54597388e26.tar.gz
coinos-ui-9e07792fcdd0ba0b7c07a20fe83db54597388e26.zip
withdraw page and other fixups
Diffstat (limited to 'src/routes/[username]')
-rw-r--r--src/routes/[username]/dashboard/+page.svelte140
1 files changed, 27 insertions, 113 deletions
diff --git a/src/routes/[username]/dashboard/+page.svelte b/src/routes/[username]/dashboard/+page.svelte
index a580f349..55fe69ee 100644
--- a/src/routes/[username]/dashboard/+page.svelte
+++ b/src/routes/[username]/dashboard/+page.svelte
@@ -13,48 +13,29 @@
$: animateRate($rate);
let animateRate = (newRate) => {
- if (!accountBalanceFiat) return;
+ if (!accountBalanceFiat) return;
let t = 0;
- let newBalance = (user.account.balance * newRate / sats);
- let oldBalance = parseFloat(accountBalanceFiat);
- let diff = oldBalance - newBalance;
+ let newBalance = (user.account.balance * newRate) / sats;
+ let oldBalance = parseFloat(accountBalanceFiat);
+ let diff = oldBalance - newBalance;
clearInterval(interval);
interval = setInterval(() => {
let delta = diff * ease(t / 100);
- accountBalanceFiat = (oldBalance - delta).toFixed(2)
+ accountBalanceFiat = (oldBalance - delta).toFixed(2);
if (t > 80) clearInterval(interval);
t++;
}, 10);
};
$: user = data.user;
- $: accountBalanceFiat = accountBalanceFiat || user && $rate && (user.account.balance * $rate / sats).toFixed(2);
+ $: accountBalanceFiat =
+ accountBalanceFiat || (user && $rate && ((user.account.balance * $rate) / sats).toFixed(2));
let payreq = '',
payreqField,
- withdrawing,
loading;
- let toggle = async () => {
- payreq = '';
- withdrawing = !withdrawing;
- await tick();
- if (withdrawing) payreqField.focus();
- };
-
- let withdraw = async () => {
- loading = true;
- try {
- await post('/withdraw', { payreq });
- withdrawing = false;
- loading = false;
- } catch (e) {
- failure(e.message);
- loading = false;
- }
- };
-
$: btcPrice = f($selectedRate, user.currency);
$: accountBalanceBtc = user.account.balance / sats;
@@ -75,96 +56,29 @@
<div class="px-3 md:px-0 flex justify-center items-center mt-10 lg:mt-0 mb-20">
<div>
<h1 class="text-3xl md:text-4xl font-semibold mb-8">
- {withdrawing ? 'Withdraw' : 'Dashboard'}
+ {$t('user.dashboard.dashboard')}
</h1>
- {#if !withdrawing}
- <!-- <span class="text-secondary mx-auto text-lg font-bold" -->
- <!-- >{$t('user.dashboard.bitcoinPrice')} -->
- <!-- <span class="text-black" -->
- <!-- >{$selectedRate ? btcPrice : $t('user.dashboard.fetchingRate')}</span -->
- <!-- > -->
- <!-- </span> -->
- <!-- -->
- <h3 class="text-secondary font-bold border-b pb-1 mt-10 mb-6 w-full md:w-[500px]">
- {$t('user.dashboard.ACCOUNT_BALANCE')}
- </h3>
-
- <span class="text-3xl font-bold block mb-1">{accountBalanceSats} SAT</span>
+ <h3 class="text-secondary font-bold border-b pb-1 mt-10 mb-6 w-full md:w-[500px] uppercase">
+ {$t('user.dashboard.accountBalance')}
+ </h3>
- <span class="text-secondary text-xl block"
- >{$selectedRate ? f(accountBalanceFiat, user.currency) : $t('user.dashboard.fetchingRate')}</span
- >
-
- <div class="md:flex md:space-x-5">
- <button
- class="rounded-full border py-2 px-5 font-bold mt-4 block md:inline hover:opacity-80"
- on:click={() => goto(`/${user.username}/receive`)}>{$t('user.dashboard.receive')}</button
- >
- <button
- class="rounded-full border py-2 px-5 font-bold mt-5 md:mt-4 hover:opacity-80"
- on:click={toggle}>{$t('user.dashboard.withdraw')}</button
- >
- </div>
- {:else}
- <div class="space-y-3 w-[250px] md:w-[500px] md:pr-20">
- <button on:click={() => (withdrawing = false)}>
- <Icon icon="arrow-left" style="w-8 hover:opacity-80" />
- </button>
-
- <div>
- <!-- found missing translation -->
- <label for="invoice" class="font-bold mb-1 block">Lightning Invoice</label>
- <input
- bind:this={payreqField}
- type="text"
- name="payreq"
- required
- bind:value={payreq}
- class="block rounded-2xl p-3 w-full bg-primary"
- />
- </div>
+ <span class="text-3xl font-bold block mb-1">{accountBalanceSats} SAT</span>
- <!-- TODO -->
- <!--
- <div>
- <label for="note" class="font-bold mb-1 block">{$t('user.dashboard.optionalNote')}</label>
- <textarea name="note" rows={2} class="block border rounded-2xl p-3 w-full bg-primary" />
- </div>
--->
+ <span class="text-secondary text-xl block"
+ >{$selectedRate
+ ? f(accountBalanceFiat, user.currency)
+ : $t('user.dashboard.fetchingRate')}</span
+ >
- <button
- disabled={!payreq}
- class="{!payreq
- ? 'opacity-50'
- : 'opacity-100 hover:opacity-80'} rounded-2xl border py-3 font-bold w-full mt-2 bg-black text-white"
- on:click={withdraw}
- >
- {#if loading}
- <svg
- class="mx-auto h-6 w-6 animate-spin text-white"
- xmlns="http://www.w3.org/2000/svg"
- fill="none"
- viewBox="0 0 24 24"
- >
- <circle
- class="opacity-25"
- cx="12"
- cy="12"
- r="10"
- stroke="currentColor"
- stroke-width="4"
- />
- <path
- class="opacity-75"
- fill="currentColor"
- d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
- />
- </svg>
- {:else}
- {$t('user.dashboard.send')}
- {/if}
- </button>
- </div>
- {/if}
+ <div class="grid sm:grid-cols-2 gap-2 mt-8">
+ <button
+ class="rounded-full border py-2 px-5 font-bold hover:opacity-80 text-xl w-full mb-2"
+ on:click={() => goto(`/${user.username}/receive`)}>{$t('user.dashboard.receive')}</button
+ >
+ <button
+ class="rounded-full border py-2 px-5 font-bold hover:opacity-80 text-xl w-full mb-2"
+ on:click={() => goto('/send')}>{$t('user.dashboard.withdraw')}</button
+ >
+ </div>
</div>
</div>